﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Krile.Subsystem
{
    public static class CompatibilityControl
    {
        public enum CompatibilityDescriptLevel { Incompatible, Warning, Notify };

        public static KeyValuePair<CompatibilityDescriptLevel, string>[] CheckCompatible()
        {
            if (Core.Config.IsFirstboot)
                return null;
            List<KeyValuePair<CompatibilityDescriptLevel, string>> items = new List<KeyValuePair<CompatibilityDescriptLevel, string>>();
            // Compatibility check
            if (Core.Config.LastWriteVersion.CheckUnder(0.513))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Incompatible, Lang.Compatibility.ICT_0513_0));
                Core.Config.Appearance.Renderer.Colors = new Krile.Cores.Config._Appearance._Renderer._Colors();
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.530))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_0530_0));
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_0530_1));

            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.620))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Incompatible, Lang.Compatibility.ICT_0620_0));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.761))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Incompatible, Lang.Compatibility.ICT_076_0));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.80))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_080_0));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.81))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Warning, Lang.Compatibility.ICT_081_0));
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_081_1));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.82))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Warning, Lang.Compatibility.ICT_082_0));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.85))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                     CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_085_0));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.90))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                    CompatibilityDescriptLevel.Warning, Lang.Compatibility.ICT_090_0));

                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                    CompatibilityDescriptLevel.Incompatible, Lang.Compatibility.ICT_090_1));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.923))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                    CompatibilityDescriptLevel.Warning, Lang.Compatibility.ICT_0923_0));
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                    CompatibilityDescriptLevel.Incompatible, Lang.Compatibility.ICT_092_0));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.997))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                    CompatibilityDescriptLevel.Warning, Lang.Compatibility.ICT_0997_0));
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                    CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_0997_1));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(0.998))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                    CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_0998_0));
            }
            if (Core.Config.LastWriteVersion.CheckUnder(1.02))
            {
                items.Add(new KeyValuePair<CompatibilityDescriptLevel, string>(
                   CompatibilityDescriptLevel.Notify, Lang.Compatibility.ICT_102_0));
            }
            return items.ToArray();
        }

        public static bool CheckUnder(this double var, double check)
        {
            return var < check;
        }
    }
}
